package com.fjt.book_pay.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fjt.book_pay.pojo.Order;


public interface IOrderDao {
	@Results({
		@Result(property = "order_id", column = "order_id"),
		@Result(property = "buy_time", column = "buy_time"),
		@Result(property = "get_time", column = "get_time"),
		@Result(property = "address", column = "address"),
		@Result(property = "state", column = "state"),
		@Result(property = "product_id", column = "product_id"),
		@Result(property = "product_number", column = "product_number"),
		@Result(property = "buyer_name", column = "buyer_name"),
		@Result(property = "seller_name", column = "seller_name"),
		@Result(property = "assess", column = "assess")}
	)
	@Select("select * from p_order where order_id=#{order_id}")
	public Order selectOrderById(@Param("order_id") int order_id);
	
	@Select("Select * from p_order where buyer_name=#{buyer_name}")
	public List<Order> selectUserAllOrder(@Param("buyer_name")String username);
	
	@Select("Select * from p_order where seller_name=#{seller_name}")
	public List<Order> selectMySellOrder(@Param("seller_name")String seller_name);
	
	@Select("Select * from p_order where product_id=#{product_id}")
	public List<Order> selectProductAllOrder(@Param("product_id")int product_id);
	
	@Insert("Insert into p_order VALUES(#{order_id},#{buy_time},#{get_time},#{address},#{state},#{product_id},#{product_name},#{product_number},#{buyer_name},#{seller_name},#{assess})")
	public boolean addOrder(Order order);

	@Update("update p_order set state=#{state} where order_id=#{order_id}")
	public boolean changeOrderState(@Param("state")String state,@Param("order_id") int order_id);

	@Update("update p_order set assess=#{assess} where order_id=#{order_id}")
	public boolean assessOrder(@Param("assess")String assess,@Param("order_id") int order_id);
	
	@Delete("delete * from p_order where order_id=#{order_id}")
	public boolean deleteOrder(@Param("order_id") int order_id);
	
	
}
